package com.itheima.service.impl;

import com.itheima.entity.QrtzBlobTriggers;
import com.itheima.dao.QrtzBlobTriggersDao;
import com.itheima.service.QrtzBlobTriggersService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (QrtzBlobTriggers)表服务实现类
 *
 * @author makejava
 * @since 2022-01-16 15:48:51
 */
@Service("qrtzBlobTriggersService")
public class QrtzBlobTriggersServiceImpl implements QrtzBlobTriggersService {
    @Resource
    private QrtzBlobTriggersDao qrtzBlobTriggersDao;

    /**
     * 通过ID查询单条数据
     *
     * @param schedName 主键
     * @return 实例对象
     */
    @Override
    public QrtzBlobTriggers queryById(String schedName) {
        return this.qrtzBlobTriggersDao.queryById(schedName);
    }

    /**
     * 分页查询
     *
     * @param qrtzBlobTriggers 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<QrtzBlobTriggers> queryByPage(QrtzBlobTriggers qrtzBlobTriggers, PageRequest pageRequest) {
        long total = this.qrtzBlobTriggersDao.count(qrtzBlobTriggers);
        return new PageImpl<>(this.qrtzBlobTriggersDao.queryAllByLimit(qrtzBlobTriggers, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param qrtzBlobTriggers 实例对象
     * @return 实例对象
     */
    @Override
    public QrtzBlobTriggers insert(QrtzBlobTriggers qrtzBlobTriggers) {
        this.qrtzBlobTriggersDao.insert(qrtzBlobTriggers);
        return qrtzBlobTriggers;
    }

    /**
     * 修改数据
     *
     * @param qrtzBlobTriggers 实例对象
     * @return 实例对象
     */
    @Override
    public QrtzBlobTriggers update(QrtzBlobTriggers qrtzBlobTriggers) {
        this.qrtzBlobTriggersDao.update(qrtzBlobTriggers);
        return this.queryById(qrtzBlobTriggers.getSchedName());
    }

    /**
     * 通过主键删除数据
     *
     * @param schedName 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String schedName) {
        return this.qrtzBlobTriggersDao.deleteById(schedName) > 0;
    }
}
